package com.itheima.duotai2;

public class Test {


    public static void main(String[] args) {
        useAnimal(new Dog());

        useAnimal(new Cat());
        useAnimal(new Pig());

    }


    public static void useAnimal(Animal a){
        a.useSing();
        a.eat();
        if(a instanceof  Dog){
            Dog d=(Dog)a;//ClsasCastException
            d.kanMen();
        }


    }
    public static void useDog(Dog a){

        a.eat();
        a.kanMen();
    }
    public static void useCat(Cat a){

        a.eat();
    }

}

abstract class Animal {

    private void sing(){
        System.out.println("唱个歌");
    }

    public void useSing(){
        this.sing();
    }
    abstract void eat();
}

class Dog extends Animal{


    @Override
    void eat() {
        System.out.println("狗吃狗粮");
    }

    public void kanMen(){
        System.out.println("狗看门");
    }
}
class Cat extends Animal{


    @Override
    void eat() {
        System.out.println("猫吃狗粮");
    }
}
class Pig extends Animal{
    @Override
    void eat() {
        System.out.println("猪吃饲料");
    }
}